interface IQueue<T> {
  enqueue(el: T): void;
  dequeue(): T | undefined;
  peek(): T | undefined;
  isEmpty(): boolean;
  size: number;
}

class ArrayQueue<T> implements IQueue<T> {
  peek(): T | undefined {
    throw new Error("Method not implemented.");
  }

  protected data: T[] = [];

  //入队方法
  enqueue(el: T): void {
    this.data.push(el);
  }

  //出队
  dequeue(): T | undefined {
    return this.data.shift();
  }

  //第一个元素
  front(): T | undefined {
    return this.data[0];
  }

  //是否是空的
  isEmpty(): boolean {
    return this.data.length === 0;
  }

  //元素个数
  get size(): number {
    return this.data.length;
  }
}

class ArrayDequeue<T> extends ArrayQueue<T> {
  addFront(value: T) {
    this.data.unshift(value);
  }

  removeBack(): T | undefined {
    return this.data.pop();
  }

  getData() {
    return this.data;
  }
}

const dequeue = new ArrayDequeue<string>();
dequeue.enqueue("aaa");
dequeue.enqueue("bbb");
dequeue.enqueue("ccc");
dequeue.enqueue("ddd");
dequeue.enqueue("abc");

console.log(dequeue.getData());

while (!dequeue.isEmpty()) {
  console.log(dequeue.removeBack());
}
